package com.xiaotu.controller;

import com.xiaotu.pojo.Comment;
import com.xiaotu.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
public class CommentController {
    @Autowired
    @Qualifier("apiRedisCommentServiceImpl")
    private CommentService commentService;

    @GetMapping("/get/{id}")
    public Comment findById(@PathVariable("id")Integer id){
        Comment byId = commentService.findById(id);
        return byId;
    }
    @GetMapping("/update/{id}/{author}")
    public Comment updateComment(@PathVariable("id")Integer id,
                                 @PathVariable("author")String author){
        Comment comment = commentService.findById(id);
        comment.setAuthor(author);
        Comment updateComment = commentService.updateComment(comment);
        return updateComment;
    }
    @GetMapping("/delete/{id}")
    public void deleteComment(@PathVariable("id")Integer id){
        commentService.deleteComment(id);
    }
}
